function showEDUOther(selection)
{
	if(selection == "other") 
	{
		document.getElementById("eduOther").style.display='block';
		document.getElementById("eduReq").setAttribute("required", "required");
	}	
	else
	{
		document.getElementById("eduOther").style.display= 'none';
		document.getElementById("eduReq").removeAttribute("required");
	}
}

function showInfoOther(selection)
{
		if(selection == "other")
		{
			document.getElementById('infoOther').style.display= 'block';
			document.getElementById('infoReq').setAttribute("required", "required");
		}
		else
		{
			document.getElementById('infoOther').style.display= 'none';
			document.getElementById('infoReq').removeAttribute('required');
		}
}

function validateChars(field, field2)
{
	if (field =="")
	{
		return;
	}
	else
	{
		var id = field2;
		var temp = field;
		var rxcL = /[A-Z][a-z][A-z]/gi;
		var rxn = /[0-9][\^=+-}{\\|';\/.,?"`~$!@#$%^&*)(]/g;

		if (rxcL.test(temp))// && rxcG.test(field))
		{
			if (rxn.test(temp)) {
				document.getElementById("errorMsg").innerHTML="Παρακαλούμε εισάγετε έγκυρους χαρακτήρες, χωρίς νούμερα.";
				document.getElementById(id).value= "";
				document.getElementById(id).setAttribute('style', 'background-color:#FF9999');
				document.getElementById("errorMsg").style.display= 'block';
				document.getElementById("errorMsg").style.color='red';
				
			} else {
				document.getElementById("errorMsg").style.display= 'none';
				document.getElementById(id).removeAttribute('style');
			}
		} else {
			if (!rxn.test(temp)) {
				document.getElementById("errorMsg").style.display= 'none';
			} else {
				document.getElementById("errorMsg").innerHTML="Παρακαλούμε εισάγετε έγκυρους χαρακτήρες, χωρίς νούμερα.";
				document.getElementById(id).value= "";
				document.getElementById(id).setAttribute('style', 'background-color:#FF9999');
				document.getElementById("errorMsg").style.display= 'block';
				document.getElementById("errorMsg").style.color='red';
			}

		}

	}
}

function validateNums(field, field2)
{
	if (field =="")
	{
		return;
	}
	else
	{
		var id = field2;
		var rxn = /[\^=+-}{\\|';\/.,?"`~$!@#$%^&*)(][a-z][A-Z][A-z]/g;
		var temp = field;
		var rxnt=/[0-9][^a-z][^A-Z][^A-z]/gim;
		
			if(rxnt.test(temp) && !rxn.test(temp))
			{
					document.getElementById("errorMsg").style.display= 'none';
					document.getElementById(id).removeAttribute('style');
					if(field2 == 'afm' && !checkAFM(temp))
					{
						document.getElementById("errorMsg").innerHTML="Το ΑΦΜ που εισάγατε δεν είναι έγκυρο!";
						document.getElementById(id).value= "";
						document.getElementById(id).setAttribute('style', 'background-color:#FF9999');
						document.getElementById("errorMsg").style.display= 'block';
						document.getElementById("errorMsg").style.color='red';
					}
			}
			else
			{
				document.getElementById("errorMsg").innerHTML="Παρακαλούμε εισάγετε έγκυρα νούμερα, χωρίς χαρακτήρες!";
				document.getElementById(id).value= "";
				document.getElementById(id).setAttribute('style', 'background-color:#FF9999');
				document.getElementById("errorMsg").style.display= 'block';
				document.getElementById("errorMsg").style.color='red';
			}
			
	}
}

function updateFields(parentID, value, values)
{
	var val = value;
	if(val == 'Array')
	{
		var output ="";
		document.getElementById("department").style.display = 'block';
		
		for (var i=0; i < values.length; i++) {
			output+="<option value=\""+values[i]+"\">"+values[i]+"</option>";
		};
		document.getElementById("depExtra").innerHTML=output;
	}
	else if (val != "")
	{
		document.getElementById("department").style.display = 'block';
		document.getElementById("depExtra").innerHTML="<option value=\""+String(val)+"\">"+String(val)+"</option>";
	}
	else
	{
		document.getElementById("department").style.display = 'none';
		document.getElementById("depExtra").innerHTML="";
	}
	return;
}

function checkAFM (afm){

if(afm.length <9 || afm == '000000000')
	return false;
var iDigit = 0;
var Num1 = 0;
for(iDigit= 1; iDigit <=  8; iDigit++){
Num1+=parseInt(afm.substr(iDigit-1,1)) * Math.pow(2,(9-iDigit));
}
var res = Num1 % 11;
if(res == 10) { res=0;}
return (res == afm.substr(afm.length-1,1)) ? true : false ;
};

function isValidIBAN($v){ //This function check if the checksum if correct
			$v = $v.replace(/^(.{4})(.*)$/,"$2$1"); //Move the first 4 chars from left to the right
			$v = $v.replace(/[A-Z]/g,function($e){return $e.charCodeAt(0) - 'A'.charCodeAt(0) + 10}); //Convert A-Z to 10-25
			var $sum = 0;
			var $ei = 1; //First exponent 
			for(var $i = $v.length - 1; $i >= 0; $i--){
				$sum += $ei * parseInt($v.charAt($i),10); //multiply the digit by it's exponent 
				$ei = ($ei * 10) % 97; //compute next base 10 exponent  in modulus 97
			}; 
			return $sum % 97 == 1;
		}
		var $patterns={ //Map automatic generated by IBAN-Patterns Online Tool
				'IBAN-GR': function($v){ //Greece 
					return /^GR\d{9}[0-9A-Z]{16}$/.test($v) && isValidIBAN($v);
				}
		};
		
function check_iban(iban)
{
	if (isValidIBAN(iban))
	{
		document.getElementById("errorMsg").style.display= 'none';
		document.getElementById('iban').removeAttribute('style');
	}
	else
	{
		document.getElementById("errorMsg").innerHTML="Ο κωδικός IBAN δεν είναι έγκυρος!";
		document.getElementById('iban').value= "";
		document.getElementById('iban').setAttribute('style', 'background-color:#FF9999');
		document.getElementById("errorMsg").style.display= 'block';
		//document.getElementById("errorMsg").style.color='red';
	}
};
